package org.me.client;

import com.gwt.components.client.Canvas;
import org.gwtwidgets.client.style.Color;
import org.gwtwidgets.client.svg.*;

public class Graphes {
public static Canvas plot2D(float[][] A, int width, int height) {
		Canvas ctx = new Canvas(width, height);
		if (AlgebraNumeerica.EsMatriz(AlgebraNumeerica.float2Float(A)) == false || A[0].length != 2) {
			ctx.beginPath();
			ctx.moveTo(0, 0);
			ctx.setStrokeColor("red");
			ctx.lineTo(width, height);
			ctx.moveTo(0, height);
			ctx.lineTo(width, 0);
			ctx.stroke();
			ctx.setFillStyle("red");
			ctx.arc((float)width / 2, (float)height / 2, (float)(width + height) / 100, (float) 0, 2 *(float) Math.PI
					, false);
			ctx.fill();
			return ctx;
		} else {

			ctx.beginPath();
			ctx.setStrokeColor("black");
			ctx.setLineWidth(2);
			ctx.moveTo(0, height);
			ctx.lineTo(0, 0);
			ctx.moveTo(0, height);
			ctx.lineTo(width, height);
			ctx.moveTo(0, height);
			ctx.stroke();
			for (int i = 0; i < A.length; i++) {
				ctx.arc((float)width / 2, (float)height / 2, (float)(width + height) / 100, (float) 0, 2 *(float) Math.PI
						, false);
				ctx.fill();
			}
			return ctx;
		}
	}
	public static SVGPanel plot2D_SVG(float[][] A, int width, int height) {
		SVGPanel panel = new SVGPanel(width, height);
		// ligne.setColor(new Color(0, 0, 0));
		SVGPath path=panel.createPath(0.0, 0.0);
		path.setColor(new Color(0,0,0));
		path.setStrokeWidth(3);
		path.lineTo(width,height);
		return panel;
	}

	public static Canvas Beispiel_EinesFroehlichenGeschichts(){
		final Canvas			ctx												= new Canvas(200, 200);
		ctx.beginPath();
		ctx.arc(75, 75, 50, 0, (float) Math.PI * 2, true); // Outer circle
		ctx.moveTo(110, 75);
		ctx.arc(75, 75, 35, 0, (float) Math.PI, false); // Mouth (clockwise)
		ctx.moveTo(65, 65);
		ctx.arc(60, 65, 5, 0, (float) Math.PI * 2, true); // Left eye
		ctx.moveTo(95, 65);
		ctx.arc(90, 65, 5, 0, (float) Math.PI * 2, true); // Right eye
		ctx.stroke();
		// path.curveToA(20,20,(float)2*Math.PI,true,true,20,30);
		return ctx;
	}


}
